// 1. 阿珂喜欢吃香蕉
pub fn binary_search(v: &Vec<i32>, des: u8) -> i8 {
    let mut left = 1;
    let mut right = *v.iter().max().unwrap();
    while left < right {
        let mid = (left + right) >> 1;
        if can_eat(v, mid, des) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    left as i8
}

fn can_eat(v: &Vec<i32>, speed: i32, h: u8) -> bool {
    let mut sum = 0;
    for i in v.into_iter() {
        let temp = (*i as f32/speed as f32).ceil() as u8;
        sum += temp;
    }
    sum <= h
}

// 2. x 的平方根
pub fn my_sqrt(x: u32) -> u32 {
    let mut left = 1.;
    let mut right = x as f64;
    let mut mid = 0.;
    let mut temp = 0.;
    while (temp - x as f64).abs() > 0.000001 {
        mid = (left + right)/2.;
        temp = mid*mid;
        if temp > x as f64 {
            right = mid;
        } else {
            left = mid;
        }
    }
    return mid as u32;
}